<template>
	<view class="">

		<view class="zheq" @click="aa" v-if="examine!=1">

		</view>
		<view class="zhuce" v-if="showexamine=='1'">

		</view>
		<view class="zhuce-card" v-if="showexamine=='1'">
			<view class="button-zhu" @click="zhceFn">
				立即注册
			</view>
			<view class="button-no" @click="showFn">
				暂不注册
			</view>
		</view>
		<diy ref="diy" v-if="isDiy && loading" :examine="examine"></diy>
		<visualization ref='vis' v-else-if="!isDiy && loading"></visualization>

	</view>

</template>

<script>
	import diy from './diy'
	import visualization from './visualization'
	import Cache from '@/utils/cache';
	import {
		getUserInfo
	} from "@/api/user.js";
	import {
		getShare,
		getVersion
	} from "@/api/public.js";
	import {
		mapGetters
	} from "vuex";
	let app = getApp();
	export default {
		data() {
			return {
				isDiy: uni.getStorageSync('is_diy'),
				shareInfo: {},
				loading: false,
				// 判断是否注册
				examine: '0',
				// 控制弹出注册卡片
				showexamine: '0',
			}
		},
		components: {
			diy,
			visualization
		},
		onLoad() {
			let that=this
			uni.hideTabBar()
			// uni.$on('is_diy', (data) => {
			// 	this.isDiy = data
			// })
			this.setOpenShare();
			// console.log(this.isLogin);
			  that.$refs.diy.diyData()
			  // that.$refs.diy.getGoodsList()
			  // that.$refs.diy.$refs.goodlist.productslist()
			  console.log('onload');
		},
		onShow() {
			let that=this
			this.getVersion(0);
			// this.getUserInfo();
			this.userfn()
			this.showexamine = '0'
			   that.$refs.diy.diyData()
			    // that.$refs.diy.$refs.goodlist.productslist()
			   console.log('onshow');
			
		},
		onHide() {
			// this.isDiy = -1
			// console.log('离开1122222211');
		},
		computed: mapGetters(['isLogin']),
		methods: {
			panduaan() {
				let that = this;
				if (this.examine == '0') {
					this.showexamine = '1'
				} else if (this.examine == '2') {
					uni.showToast({
						title: '正在审核请稍后',
						duration: 1000,
						icon: 'none'
					});
					return false
				}
			},
			aa() {
				console.log(12);
				// if(this.isLogin){
				this.getUserInfo()
				this.panduaan()
				// }else{

				// }
				console.log(this.isLogin);
			},
			userfn() {
				if (this.isLogin) {

					this.getUserInfo()
				}
			},
			getUserInfo: function() {

				let that = this;
				console.log('11111111');
				getUserInfo().then((res) => {

					that.$set(that, "examine", res.data.examine);
					console.log(res, 'res555555555555');
				});
			},
			showFn() {
				this.showexamine = '0'
			},
			zhceFn() {
				uni.navigateTo({
					url: '/pages/goods_details/register'
				})
				this.showexamine = '0'
			},

			getVersion(name) {
				uni.$emit('uploadFooter')
				getVersion(name).then(res => {
					this.version = res.data.version
					this.isDiy = res.data.is_diy
					this.loading = true
					uni.setStorageSync('is_diy', res.data.is_diy)
					if (!uni.getStorageSync('DIY_VERSION') || res.data.version != uni.getStorageSync(
							'DIY_VERSION')) {
						if (uni.getStorageSync('DIY_VERSION')) {
							uni.setStorageSync('DIY_VERSION', res.data.version)
							if (this.isDiy) {
								this.$refs.diy.reconnect()
							} else {
								this.$refs.vis.reconnect()
							}
						}
						uni.setStorageSync('DIY_VERSION', res.data.version)
					} else {}
				}).catch(err => {
					// #ifdef APP-PLUS
					setTimeout(e => {
						this.getVersion(0);
					}, 1500)
					// #endif
					// #ifndef APP-PLUS
					this.$util.Tips({
						title: err
					});
					// #endif
				})
			},
			// 微信分享；
			setOpenShare: function() {
				let that = this;
				getShare().then((res) => {
					let data = res.data;
					this.shareInfo = data;
					// #ifdef H5
					let url = location.href;
					if (this.$store.state.app.uid) {
						url =
							url.indexOf("?") === -1 ?
							url + "?spread=" + this.$store.state.app.uid :
							url + "&spread=" + this.$store.state.app.uid;
					}
					if (that.$wechat.isWeixin()) {
						let configAppMessage = {
							desc: data.synopsis,
							title: data.title,
							link: url,
							imgUrl: data.img,
						};
						that.$wechat.wechatEvevt(
							["updateAppMessageShareData", "updateTimelineShareData"],
							configAppMessage
						);
					}
					// #endif
				});
			},
		},
		onReachBottom: function() {
			if (this.isDiy) {
				this.$refs.diy.onsollBotton()
			}
		},
		// 滚动监听
		onPageScroll(e) {
			// 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
			uni.$emit('scroll');
		},
		// #ifdef MP
		//发送给朋友
		onShareAppMessage(res) {
			// 此处的distSource为分享者的部分信息，需要传递给其他人
			let that = this;
			return {
				title: this.shareInfo.title,
				path: "/pages/index/index?spid=" + this.$store.state.app.uid || 0,
				imageUrl: this.shareInfo.img,
			};
		},
		//分享到朋友圈
		onShareTimeline() {
			return {
				title: this.shareInfo.title,
				query: {
					spid: this.$store.state.app.uid || 0
				},
				imageUrl: this.shareInfo.img,
			};
		},
		// #endif
	}
</script>

<style scoped lang="scss">
	.footer-f{
		margin-top: 30rpx;
		text-align: center;
		color: #ccc;
		font-size: 20rpx;
	}
	.zheq {
		position: fixed;
		// width: 100%;
		// height: 100vh;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 999;
		background-color: transparent;
		// background-color: red;
	}

	.zhuce {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		opacity: 0.4;
		background: #000000;
		z-index: 999;

	}

	.zhuce-card {
		background-image: url('https://shengyueimg.changlaidongpin.cn/attach/2024/01/9ec5e202401271002291345.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 618rpx;
		height: 714rpx;
		position: absolute;
		transform: translate(-50%, -50%);
		top: 50%;
		left: 50%;
		z-index: 999;

		.button-zhu {
			margin-top: 474rpx;
			margin-left: 28rpx;
			width: 562rpx;
			height: 96rpx;
			background: linear-gradient(180deg, #9BFF5E 0%, #48E14E 100%);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			text-align: center;
			line-height: 96rpx;
			font-size: 40rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}

		.button-no {
			margin-top: 54rpx;
			text-align: center;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #777777;

		}
	}
</style>